package com.supeng.PMdepot.adapter;

import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.supeng.PMdepot.R;
import com.supeng.PMdepot.entity.WfChaXiang;

/**
 * 外发拆箱
 * Created by Supeng on 2018/8/23.
 */
//Caption been
public class WfChaXiangAdapter extends BaseQuickAdapter<WfChaXiang, BaseViewHolder> {
    private EtOncliLisnter etOncliLisnter;

    public EtOncliLisnter getEtOncliLisnter() {
        return etOncliLisnter;
    }

    public void setEtOncliLisnter(EtOncliLisnter etOncliLisnter) {
        this.etOncliLisnter = etOncliLisnter;
    }

    public WfChaXiangAdapter() {
        //item layout
        super(R.layout.layout_wf_chaixiang_item);
    }
    //设置控件数据
    @Override
    protected void convert(final BaseViewHolder helper, WfChaXiang item) {
        if(helper.getAdapterPosition()==0){
            helper.setText(R.id.tv_bmcl, "剩余(重量"+item.getWeight()+"kg/数量"+item.getCount()+")");
            helper.getView(R.id.ll_et).setVisibility(View.GONE);
        }else {
            helper.getView(R.id.ll_et).setVisibility(View.VISIBLE);
            helper.setText(R.id.tv_bmcl,  "表面处理("+item.getColor()+")");
            EditText editTextWeight=helper.getView(R.id.et_cha_weight);

            EditText editTextCount=helper.getView(R.id.et_cha_count);
            editTextCount.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

                    if (actionId == 6||actionId == 5) {
                        if(etOncliLisnter!=null){
                            etOncliLisnter.etCount(v,helper.getAdapterPosition());
                        }
                    }
                    return true;

                }
            });
            editTextWeight.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

                    if (actionId == 6||actionId == 5) {
                        if(etOncliLisnter!=null){
                            etOncliLisnter.etWeight(v,helper.getAdapterPosition());
                        }
                    }
                    return true;

                }
            });
            editTextWeight.setText(item.getWeight()==0?"":item.getWeight()+"");
            editTextCount.setText(item.getCount()==0?"":item.getCount()+"");
        }


    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        //holder.setIsRecyclable(false);
    }
    public  interface EtOncliLisnter{
        public void etWeight(TextView v,int position);
        public void etCount(TextView v,int position);
    }
}
